$(function () {
    obj.init();
});

var obj = new function () {
    return {
        id: null,
        form: null,
        commitForm: null,
        isEnd: 0,
        init: function () {
            this.id = xhTool.getQuery('id');
            this.form = $('#refuseCommitForm');
            this.commitForm = new xhForm(this.form);
            this.commitForm.parse().bindRequired($('#bt_modal_confirm',parent.document));
            this.listener();
        },
        listener: function () {
            var $this = this;
            $('#purpose').unbind('change').on('change',function () {//修改用途
                $this.funObj().bindProduct();
            });
            $('#bt_modal_confirm',parent.document).click(function () {
                $this.funObj().saveData();
            });
            $("#checkEnd").on("click", function(){
                if ($(this).is(":checked")) {
                    $this.isEnd = 1;
                } else {
                    $this.isEnd = 0;
                }
            });
        },
        funObj: function () {
            var form = this.form;
            var $this = this;
            return {
                saveData: function () {
                    var commitMsg = $('#commitMsg').val();
                    xhExtra.ajaxRequest('res/saveRefuseCommit', {id: $this.id, commitMsg:commitMsg, isEnd:$this.isEnd},
                        {success: true,check:false},function (res) {
                            if (res.code === 200) {
                                window.top.swal('成功',res.msg,'success');
                                window.top.xhTop.closeModal();
                            } else {
                                window.top.xhTop.showError(res.error);
                                xhExtra.setBtnNormal($('#bt_modal_confirm',parent.document));
                            }
                            window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        });
                },
                bindProduct: function () {
                }
            }
        }
    }
};
